package com.mxpio.erp.quality.service.impl;

import com.mxpio.erp.common.quality.entity.VEInspectionBillPassRate;
import com.mxpio.erp.common.quality.entity.VEInspectionBillSupplierPassRate;
import com.mxpio.erp.common.quality.service.VEInspectionBillPassRateService;
import com.mxpio.erp.common.quality.service.VEInspectionBillSupplierPassRateService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.lin.Linq;
import com.mxpioframework.jpa.query.Criteria;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class VEInspectionBillSupplierPassRateServiceImpl implements VEInspectionBillSupplierPassRateService {
    @Override
    @Transactional(readOnly = true)
    public List<VEInspectionBillSupplierPassRate> getPassRate(Criteria criteria) {
        Linq linq = JpaUtil.linq(VEInspectionBillSupplierPassRate.class);
        return linq.aliasToBean(VEInspectionBillSupplierPassRate.class).select("year","applyOrgName",
                        linq.criteriaBuilder().sum(linq.root().get("quantity")).alias("quantity"),
                        linq.criteriaBuilder().sum(linq.root().get("receiveQuantity")).alias("receiveQuantity"))
                .where(criteria)
                .groupBy("year","applyOrgName")
                .list();
    }
}
